<?php
namespace app\admin\controller;
use think\Controller;
use app\admin\Model\Message;
use app\admin\Model\Number;
use app\admin\Model\Pay;
use app\admin\Model\Url as U;
use think\Db;
class Index extends Common
{
	public function index(){
	$session = Session('l_id');
	//$array = explode(",",$session);
	//print_r($array);
//		echo $session;
//			die;
			$url = new U();
			
				$list = $url::where('u_id','in',$session)->select();
				
			
		
		//halt($list);
			
		return $this->fetch('index',['list'=>$list]);
	}
	public function list(){
		
		$list = Message::with('number')->with('type')->with('pay')->with('rom')->paginate(4);
		$page = $list->render();
	  //halt($list);
		
		return $this->fetch('list',['list'=>$list,'page'=>$page]);
	}
	public function add(){
		
		$mes = new Message();
		if(input("?param.sub")){
			$result = $mes->add();
			
			if($result){
				$this->success("添加成功","index/list");
			}else{
				$this->error("添加失败");
			}
		}else{
			//$data  = \app\index\model\Class1::getList();
			$pay = new Pay();
			$list1 = Pay::all();
			//halt($list1);
			$num = new Number();
			$list = Number::all();
			$this->assign('list1',$list1);
			$this->assign('list',$list);
			return $this->fetch();
		}
	}
	public function update(){
		$mes = new Message();
		
		if(input("?param.sub")){
			
			$result = $mes->upd();
			
			if($result){
				$this->success("修改成功","index/list");
			}else{
				$this->error("修改失败");
			}
		}else{
			$pay = new Pay();
			$list1 = Pay::all();
			$num = new Number();
			$list = Number::all();
			
			$id = input('param.id');
    	
    	$data = Message::get($id);
    	$this->assign('list1',$list1);
    	$this->assign('data',$data);
    	$this->assign('list',$list);
        return $this->fetch();
		}
	}
	public function list1(){
	    $data = Db::table('house_rom')->where('n_id',input('param.r_id'))->select();
	    
	    return json($data);
    }
}
?>